package day04;

/**
 * @author tongchen
 * @create 2022-12-26 23:33
 */
    public class Solution {
    public static void main(String[] args) {
        int[]arr={2,2,2,2,2,1};
        System.out.println(minNumberInRotateArray(arr));
    }
        public static int minNumberInRotateArray(int [] array) {
            //判断数组的有效性
            if(array.length==0||array==null){
                return 0;
            }
            int left=0;
            int right=array.length-1;
            //终止条件是left+1==right
            while(left+1<right){
                //优先处理特殊情况
                int mid=(left+(right-left)/2);
                if(array[left]==array[mid]&&array[mid]==array[right]){
                    //直接遍历进行查找
                    int min=array[left];
                    for(int i=left+1;i<=right;i++){
                        if(array[i]<min){
                            min=array[i];
                        }
                    }
                    return min;
                }
                //处理正常情况
                if(array[mid]>=array[left]){
                    left=mid;
                }
                else if(array[mid]<array[left]){
                    right=mid;
                }

            }
            return array[right];

        }
    }

